//
//  MCBodyDataApi.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/28.
//

import Foundation
import Moya


/*
 
 abdomen    腹围        false
 string
 arm    手臂围        false
 string
 bust    胸围        false
 string
 fat    体脂        false
 string
 height    身高：cm        false
 string
 pygal    臀围        false
 string
 shank    小腿围        false
 string
 thigh    大腿围        false
 string
 waist    腰围        false
 string
 weight    体重:kg
 */
enum MCBodyDataApi {
    case getBodyData
    case getBodyDataStatistics
    case setBodyData(height:String?,weight:String?,fat:String?,bust:String?,waist:String?,adbomen:String?,pypal:String?,arm:String?,thigh:String?,shank:String?)
}

extension MCBodyDataApi:TargetType {
    
    var baseURL: URL {
        return URL.init(string: Moya_baseURL)!
    }
    
    var path: String {
        switch self {
        case .getBodyData:
            return "api/app/user/getUserBody"
        case .getBodyDataStatistics:
            return  "api/app/user/getUserBodyTotal"
        case .setBodyData:
            return "api/app/user/saveUserBody"
       
        }
    }
    var method:Moya.Method {
        switch self {
        case .getBodyData,.getBodyDataStatistics:
            return .get
        case .setBodyData:
            return .post
        }
    }
    
    var sampleData: Data {
        return Data()
    }
    
    
    var task: Task {
        switch self {
        case .getBodyData,.getBodyDataStatistics:
            return .requestPlain
        case let .setBodyData(height, weight, fat, bust, waist, adbomen, pypal, arm, thigh, shank):
            return .requestParameters(parameters: ["height":height ?? "","weight":weight ?? "","fat":fat ?? "","bust":bust ?? "","waist":waist ?? "","adbomen":adbomen ?? "","pypal":pypal ?? "","arm":arm ?? "","thigh":thigh ?? "", "shank":shank ?? ""], encoding: JSONEncoding.default)
        
        }
    }
    
    var headers: [String : String]? {
        
        let tokenName:String = UserDefaults.standard.string(forKey: "LoginName") ?? ""
        let tokenValue:String = UserDefaults.standard.string(forKey: "LoginToken") ?? ""
        switch self {
        case .getBodyData,.getBodyDataStatistics,.setBodyData:
            return [tokenName:tokenValue]
        }
        
    }
    
    
}
